package com.hzhr.iot.device.convertor;

import com.hzhr.iot.device.convertor.custom.*;
import com.hzhr.iot.core.util.HzhrTypeUtil;
import com.hzhr.iot.core.util.HzhrJsonUtil;
import java.util.Map;
import com.hzhr.iot.device.model.options.OptionsModel;
import com.hzhr.iot.device.entity.OptionsEntity;
import com.hzhr.iot.device.entity.ext.OptionsEntityExt;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.hzhr.iot.device.model.options.OptionsModel;
import com.hzhr.iot.device.model.options.OptionsGetModel;
import com.hzhr.iot.device.queryModel.custom.OptionsCustomQueryModel;

@Component
public class OptionsConvertor {
    @Autowired
    AlarmDataCustomConvertor alarmDataCustomConvertor;
    @Autowired
    CollectDataCustomConvertor collectDataCustomConvertor;
    @Autowired
    CollectDeviceCustomConvertor collectDeviceCustomConvertor;
    @Autowired
    CollectDeviceTypeCustomConvertor collectDeviceTypeCustomConvertor;
    @Autowired
    DeviceInfoCardCustomConvertor deviceInfoCardCustomConvertor;
    @Autowired
    DeviceMaintenanceCardCustomConvertor deviceMaintenanceCardCustomConvertor;
    @Autowired
    DeviceMaintenanceCardItemCustomConvertor deviceMaintenanceCardItemCustomConvertor;
    @Autowired
    ImplFactoryCustomConvertor implFactoryCustomConvertor;
    @Autowired
    ImplIotDeviceTypeCustomConvertor implIotDeviceTypeCustomConvertor;
    @Autowired
    ImplRecordCustomConvertor implRecordCustomConvertor;
    @Autowired
    IotDeviceCustomConvertor iotDeviceCustomConvertor;
    @Autowired
    IotDeviceTypeCustomConvertor iotDeviceTypeCustomConvertor;
    @Autowired
    ProdFactoryCustomConvertor prodFactoryCustomConvertor;
    @Autowired
    RegulatorCollectDataCustomConvertor regulatorCollectDataCustomConvertor;
    @Autowired
    UserCompanyCustomConvertor userCompanyCustomConvertor;

    public OptionsEntity optionsModel2entity(OptionsModel in) {
        //未转换字段: createUserId createTime updateUserId updateTime state remarks 
        if (in == null) return null;
        OptionsEntity result = new OptionsEntity();

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setTypeName(HzhrTypeUtil.string2string(in.getTypeName()));
        result.setTypeDes(HzhrTypeUtil.string2string(in.getTypeDes()));
        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setDes(HzhrTypeUtil.string2string(in.getDes()));
        result.setCode(HzhrTypeUtil.string2string(in.getCode()));
        return result;
    }
    public OptionsEntity optionsModel2entity(OptionsModel in, OptionsEntity ori) {
        //未转换字段: createUserId createTime updateUserId updateTime state remarks 
        if (in == null) return null;
        OptionsEntity result = ori;

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setTypeName(HzhrTypeUtil.string2string(in.getTypeName()));
        result.setTypeDes(HzhrTypeUtil.string2string(in.getTypeDes()));
        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setDes(HzhrTypeUtil.string2string(in.getDes()));
        result.setCode(HzhrTypeUtil.string2string(in.getCode()));
        return result;
    }
    public List<OptionsEntity> optionsModelList2entityList(List<OptionsModel> in) {
        if (in == null) return null;
        List<OptionsEntity> result = new ArrayList<>();
        for (OptionsModel item : in) {
            result.add(optionsModel2entity(item));
        }
        return result;
    }
    public OptionsModel entity2optionsModel(OptionsEntity in) {
        //未转换字段: 
        if (in == null) return null;
        OptionsModel result = new OptionsModel();

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setTypeName(HzhrTypeUtil.string2string(in.getTypeName()));
        result.setTypeDes(HzhrTypeUtil.string2string(in.getTypeDes()));
        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setCode(HzhrTypeUtil.string2string(in.getCode()));
        result.setDes(HzhrTypeUtil.string2string(in.getDes()));
        return result;
    }
    public List<OptionsModel> entityList2optionsModelList(List<OptionsEntity> in) {
        if (in == null) return null;
        List<OptionsModel> result = new ArrayList<>();
        for (OptionsEntity item : in) {
            result.add(entity2optionsModel(item));
        }
        return result;
    }
    public OptionsModel ext2optionsModel(OptionsEntityExt in) {
        //未转换字段: 
        if (in == null) return null;
        OptionsModel result = new OptionsModel();

        result.setId(HzhrTypeUtil.integer2integer(in.getId()));
        result.setTypeName(HzhrTypeUtil.string2string(in.getTypeName()));
        result.setTypeDes(HzhrTypeUtil.string2string(in.getTypeDes()));
        result.setName(HzhrTypeUtil.string2string(in.getName()));
        result.setCode(HzhrTypeUtil.string2string(in.getCode()));
        result.setDes(HzhrTypeUtil.string2string(in.getDes()));
        return result;
    }
    public List<OptionsModel> extList2optionsModelList(List<OptionsEntityExt> in) {
        if (in == null) return null;
        List<OptionsModel> result = new ArrayList<>();
        for (OptionsEntityExt item : in) {
            result.add(ext2optionsModel(item));
        }
        return result;
    }
    public OptionsGetModel extList2optionsGetModel(List<OptionsEntityExt> extList, Integer total, Integer changeCount, Map<String, Object> query) {
        List<OptionsModel> modelList = extList2optionsModelList(extList);
        if (modelList == null) {
            OptionsGetModel result = new OptionsGetModel();
            result.setTotal(total);
            result.setChangeCount(changeCount);
            return result;
        }

         String _show = HzhrTypeUtil.object2string(query.get("_show"));
         Boolean _show_info = query.get("_show_info") != null ? Boolean.parseBoolean(query.get("_show_info").toString()) : false;

        if (!_show_info) {
            for (OptionsModel model : modelList) {
                model.setTypeName(null);
                model.setTypeDes(null);
                model.setName(null);
                model.setDes(null);
                model.setCode(null);
            }
        }

        OptionsGetModel result = new OptionsGetModel();
        if ("one".equals(_show)) {
            if (modelList.size() > 0) {
                result.setModel(modelList.get(0));
            }
         }
        if ("list".equals(_show)) {
            result.setModelList(modelList);
        }
        result.setTotal(total);
        result.setChangeCount(changeCount);
        return result;
    }
    public OptionsGetModel entity2optionsGetModel(OptionsEntity entity, Integer total, Integer changeCount, Map<String, Object> query) {
        List<OptionsEntityExt> extList = new ArrayList<>();
        if (entity == null) return extList2optionsGetModel(extList, total, changeCount, query);
        extList.add(HzhrJsonUtil.convertObjectType(entity, OptionsEntityExt.class));
        return extList2optionsGetModel(extList, total, changeCount, query);
     }
    public OptionsCustomQueryModel optionsService_query2queryModel(Map<String, Object> query) {
        OptionsCustomQueryModel queryModel = new OptionsCustomQueryModel();

        Integer _equal_id = HzhrTypeUtil.object2integer(query.get("_equal_id"));
        if (_equal_id != null) {
            queryModel.setEqual_id(_equal_id);
         }

        String _equal_typeName = HzhrTypeUtil.object2string(query.get("_equal_typeName"));
        if (_equal_typeName != null) {
            queryModel.setEqual_typeName(_equal_typeName);
         }

        String _orderBy_code = HzhrTypeUtil.object2string(query.get("_orderBy_code"));
        if (_orderBy_code != null) {
            queryModel.setOrderBy_code(_orderBy_code);
         }

        Boolean _show_info = HzhrTypeUtil.object2boolean(query.get("_show_info"));
        if (_show_info != null && _show_info) {
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
            queryModel.setShow(true);
        }

        Integer page = HzhrTypeUtil.object2integer(query.get("_page"));
        Integer count = HzhrTypeUtil.object2integer(query.get("_count"));
        queryModel.setPage(page, count);

        return queryModel;
    }

}

